package com.yxh.service.impl;

import com.yxh.dao.HistoryMapper;
import com.yxh.dao.ViciousMapper;
import com.yxh.dao1.NewWorkMapper;
import com.yxh.exception.ProjectException;
import com.yxh.service.FlowManageService;
import com.yxh.service.TaskHistroyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static com.yxh.util.APIErrorCode.SELECT_ERROR;
/**
 * Created by asus on 2018/6/7.
 */

@Service
@Transactional
public class TaskHistroyServiceImpl implements TaskHistroyService {

    @Autowired
    private ViciousMapper viciousMapper;

    @Autowired
    private HistoryMapper historyMapper;

    @Autowired
    private FlowManageService flowManageService;

    @Override
    public List<Map<String, Object>> getHistrot(String id) {

        try{
            List<Map<String, Object>> llst=historyMapper.selectHistory(id);
            List<Map<String, Object>> newllst=new ArrayList<Map<String, Object>>();
            if(llst.size()!=0){
                for(Map<String, Object> map:llst){
                    if(map.get("imgId")!=null){
                        map.put("imgs",viciousMapper.getListImgs(map.get("imgId").toString()));
                    }
                        //String presideId=map.get("presideId").toString();
                    if(map.get("presideId")!=null&&!map.get("presideId").equals("")) {
                        map.put("presideName", flowManageService.nameBack(map.get("presideId").toString()));
                  }
                    newllst.add(map);
                }
                return newllst;
            }


            return llst;
        }catch(Exception e){
            e.printStackTrace();
            throw new ProjectException(SELECT_ERROR);
        }



    }

    @Override
    public Map<String, Object> get(Integer id) {
        Map<String, Object> llst=historyMapper.selectByPrimaryKey(id);
        if(llst.get("imgId")!=null){
            llst.put("imgs",viciousMapper.getListImgs(llst.get("imgId").toString()));
        }
        if(llst.get("auditingId")!=null)
            llst.put("presideName", flowManageService.nameBack(llst.get("apresideId").toString()));


        return llst;
    }
}
